<template>
	<view class="columnbox wdh-100 content">
		<image src="/static/img/indexbg.png" mode="widthFix" class="wdh-100 bg-box"></image>
		<!-- <view class="wdh-100 color-box"></view> -->
		<view class="wdh-100 columnbox info-box">
			<view class="wdh-100" :style="{'height':topHeight+'px'}"></view>
			<view class="rowbox wdh-100 spb" v-if="isLogin" @click="editInfo">
				<view class="rowbox">
					<image src="/static/img/tx.png" mode="aspectFill" class="user-tx"></image>
					<view class="columnbox als">
						<view class="user-name">{{userInfo.name||'完善个人信息'}}</view>
						<view class="user-phone">{{userInfo.phone}}</view>
					</view>
				</view>
				<u-icon name="arrow-right" size="28rpx"></u-icon>
			</view>
			<view class="rowbox wdh-100 spb" v-else @click="toLog">
				<view class="rowbox">
					<image src="/static/img/tx.png" mode="aspectFill" class="user-tx"></image>
					<view class="columnbox als">
						<view class="user-name">立即登录</view>
					</view>
				</view>
				<u-icon name="arrow-right" size="28rpx"></u-icon>
			</view>
			<view class="columnbox one-info">
				<view class="wdh-100 info-title">个人信息</view>
				<view class="wdh-100 info-list">
					<view class="columnbox one-box" @click="editInfo">
						<image src="/static/img/grxx.png" mode="widthFix"></image>
						个人信息
					</view>
					<view class="columnbox one-box" @click="showBingli">
						<image src="/static/img/wdbl.png" mode="widthFix"></image>
						我的病例
					</view>
					<view class="columnbox one-box" @click="showAddress">
						<image src="/static/img/dzgl.png" mode="widthFix"></image>
						地址管理
					</view>
					<view class="columnbox one-box" @click="showStBingli">
						<image src="/static/img/stbl.png" mode="widthFix"></image>
						实体病例
					</view>
				</view>
			</view>
			<view class="columnbox one-info">
				<view class="wdh-100 info-title">诊疗记录</view>
				<view class="wdh-100 info-list">
					<view class="columnbox one-box" @click="showOrder">
						<image src="/static/img/wddd.png" mode="widthFix"></image>
						商品订单
					</view>
					<view class="columnbox one-box" @click="zhongyaoChufang">
						<image src="/static/img/zycf.png" mode="widthFix"></image>
						中药处方
					</view>
					<view class="columnbox one-box" @click="xiyaoChufang">
						<image src="/static/img/xycf.png" mode="widthFix"></image>
						西药处方
					</view>
					<view class="columnbox one-box" @click="showWenzhen">
						<image src="/static/img/wdwz.png" mode="widthFix"></image>
						我的问诊
					</view>
				</view>
			</view>
			<view class="columnbox one-info">
				<view class="rowbox wdh-100 spb m-box" @click="showEwm">
					<view class="rowbox">
						<image class="m-img" src="/static/img/ewm.png" mode="widthFix"></image>
						我的二维码
					</view>
					<u-icon name="arrow-right" size="24rpx"></u-icon>
				</view>
				<view class="rowbox wdh-100 spb m-box" @click="callPhone">
					<view class="rowbox">
						<image class="m-img" src="/static/img/kefu.png" mode="widthFix"></image>
						联系医助
					</view>
					<u-icon name="arrow-right" size="24rpx"></u-icon>
				</view>
				<view class="rowbox wdh-100 spb m-box" @click="feedBack">
					<view class="rowbox">
						<image class="m-img" src="/static/img/yjfk.png" mode="widthFix"></image>
						意见反馈
					</view>
					<u-icon name="arrow-right" size="24rpx"></u-icon>
				</view>
				<view class="rowbox wdh-100 spb m-box" @click="showDocument('1')">
					<view class="rowbox">
						<image class="m-img" src="/static/img/myorder.png" mode="widthFix"></image>
						用户协议
					</view>
					<u-icon name="arrow-right" size="24rpx"></u-icon>
				</view>
				<view class="rowbox wdh-100 spb m-box" @click="showDocument('2')">
					<view class="rowbox">
						<image class="m-img" src="/static/img/myorder.png" mode="widthFix"></image>
						隐私协议
					</view>
					<u-icon name="arrow-right" size="24rpx"></u-icon>
				</view>
				<!-- <view class="rowbox wdh-100 spb m-box">
					<view class="rowbox">
						<image class="m-img" src="/static/img/qhjs.png" mode="widthFix"></image>
						切换角色
					</view>
					<u-icon name="arrow-right" size="24rpx"></u-icon>
				</view> -->
				<view class="rowbox wdh-100 spb m-box" v-if="isLogin" @click="quitLog">
					<view class="rowbox">
						<image class="m-img" src="/static/img/set.png" mode="widthFix"></image>
						退出登录
					</view>
					<u-icon name="arrow-right" size="24rpx"></u-icon>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				topHeight: 20
			};
		},
		computed: {
			// 通过计算属性将 state 中的 count 映射到组件
			isLogin() {
				return this.$store.state.isLogin;
			},
			userInfo() {
				return this.$store.state.user;
			},
		},
		onLoad() {
			this.topHeight = uni.getMenuButtonBoundingClientRect().height + uni.getMenuButtonBoundingClientRect().top
		},
		onShow() {
			console.log(this.userInfo)
		},
		methods: {
			showEwm() {
				// console.log(this.userInfo.erweima)
				uni.previewImage({
					urls: [this.userInfo.erweima],
					current: this.userInfo.erweima
				})
				// uni.downloadFile({
				// 	url: this.userInfo.erweima,
				// 	success: (res) => {
				// 		console.log(res)
				// 		uni.showShareImageMenu({
				// 			path: res.tempFilePath[0]
				// 		});
				// 	}
				// })

			},
			feedBack() {
				if (this.isLogin) {
					this.$isEditInfo()
					uni.navigateTo({
						url: '/packageA/feedBack/feedBack'
					})
				} else {
					this.$toLog()
				}
			},
			callPhone() {
				if (this.isLogin) {
					this.$req.post('/user/kefu', {
						uid: uni.getStorageSync('uid')
					}).then(res => {
						uni.makePhoneCall({
							phoneNumber: res.data.data
						})
					})
				} else {
					this.$toLog()
				}
			},
			// 用户协议
			showDocument(type) {
				uni.navigateTo({
					url: '/packageA/document/document?type=' + type
				})
			},
			// 中药处方
			zhongyaoChufang() {
				if (this.isLogin) {
					this.$isEditInfo()
					uni.navigateTo({
						url: '/packageA/chufang/zhongyao'
					})
				} else {
					this.$toLog()
				}
			},
			// 西药处方
			xiyaoChufang() {
				if (this.isLogin) {
					this.$isEditInfo()
					uni.navigateTo({
						url: '/packageA/chufang/xiyao'
					})
				} else {
					this.$toLog()
				}
			},
			// 商品订单
			showOrder() {
				if (this.isLogin) {
					this.$isEditInfo()
					uni.navigateTo({
						url: '/pages/order/order'
					})
				} else {
					this.$toLog()
				}
			},
			//退出登录
			quitLog() {
				uni.showModal({
					title: '是否确认退出登录',
					success: (res) => {
						if (res.confirm) {
							uni.clearStorageSync()
							this.$store.dispatch('actionsHandleUserInfoChange', '')
							this.$store.dispatch('actionsHandleIsLoginChange', false)
						}
					}
				})
			},
			// 我的问诊
			showWenzhen() {
				uni.switchTab({
					url: '/pages/chat/chat'
				})
			},
			showBingli() {
				if (this.isLogin) {
					this.$isEditInfo()
					uni.navigateTo({
						url: '/pages/bingli/list'
					})
				} else {
					this.$toLog()
				}
			},
			showStBingli() {
				if (this.isLogin) {
					this.$isEditInfo()
					uni.navigateTo({
						url: '/pages/bingli/caseList'
					})
				} else {
					this.$toLog()
				}
			},
			showAddress() {
				if (this.isLogin) {
					this.$isEditInfo()
					uni.navigateTo({
						url: '/pages/address/list'
					})
				} else {
					this.$toLog()
				}
			},
			toLog() {
				this.$toLog()
			},
			editInfo() {
				if (this.isLogin) {
					uni.navigateTo({
						url: '/pages/editinfo/editinfo'
					})
				} else {
					this.$toLog()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		min-height: 100vh;
		// background: #ebeff6;
		background: #F5F8FB;
		font-family: PingFang SC;
		justify-content: flex-start;
	}

	.bg-box {
		position: fixed;
		top: 0;
		left: 0;
	}

	.color-box {
		position: fixed;
		top: 0;
		left: 0;
		height: 500rpx;
		// background: linear-gradient(to bottom, #0fdcad, #ebeff6);
	}

	.info-box {
		position: relative;
		z-index: 2;
		padding: 40rpx 20rpx;

		.user-tx {
			width: 100rpx;
			height: 100rpx;
			border-radius: 100rpx;
			margin-right: 20rpx;
		}

		.user-name {
			font-size: 32rpx;
			font-weight: bold;
		}

		.user-phone {
			color: #374351;
			font-size: 24rpx;
			margin-top: 10rpx;
		}
	}

	.one-info {
		background: #fff;
		padding: 20rpx 20rpx;
		border-radius: 20rpx;
		width: 710rpx;
		margin-top: 40rpx;
	}

	.info-title {
		font-size: 28rpx;
		margin-bottom: 10rpx;
	}

	.info-list {
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;

	}

	.one-box {
		font-size: 24rpx;
		margin-top: 20rpx;
		width: 25%;

		image {
			width: 70rpx;
			height: 70rpx;
			margin-bottom: 10rpx;
		}
	}

	.m-box {
		padding: 32rpx 20rpx;
		font-size: 28rpx;

		.m-img {
			width: 40rpx;
			height: 40rpx;
			margin-right: 20rpx;
		}
	}
</style>